<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "region".
 *
 * @property int $id
 * @property int $regionType
 * @property int $accountId
 * @property int|null $parentRegion
 * @property string $name
 * @property float $latitude1
 * @property float $latitude2
 * @property float $longitude1
 * @property float $longitude2
 *
 * @property User $account
 * @property Forecast[] $forecasts
 * @property Region $regionType0
 * @property Region[] $regions
 * @property Weather[] $weathers
 */
class Region extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'region';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['regionType', 'accountId', 'name', 'latitude1', 'latitude2', 'longitude1', 'longitude2'], 'required'],
            [['regionType', 'accountId', 'parentRegion'], 'default', 'value' => null],
            [['regionType', 'accountId', 'parentRegion'], 'integer'],
            [['latitude1', 'latitude2', 'longitude1', 'longitude2'], 'number'],
            [['name'], 'string', 'max' => 255],
            [['regionType'], 'exist', 'skipOnError' => true, 'targetClass' => Region::class, 'targetAttribute' => ['regionType' => 'id']],
            [['accountId'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['accountId' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'regionType' => 'Region Type',
            'accountId' => 'Account ID',
            'parentRegion' => 'Parent Region',
            'name' => 'Name',
            'latitude1' => 'Latitude1',
            'latitude2' => 'Latitude2',
            'longitude1' => 'Longitude1',
            'longitude2' => 'Longitude2',
        ];
    }

    /**
     * Gets query for [[Account]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getAccount()
    {
        return $this->hasOne(User::class, ['id' => 'accountId']);
    }

    /**
     * Gets query for [[Forecasts]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getForecasts()
    {
        return $this->hasMany(Forecast::class, ['regionId' => 'id']);
    }

    /**
     * Gets query for [[RegionType0]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getRegionType0()
    {
        return $this->hasOne(Region::class, ['id' => 'regionType']);
    }

    /**
     * Gets query for [[Regions]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getRegions()
    {
        return $this->hasMany(Region::class, ['regionType' => 'id']);
    }

    /**
     * Gets query for [[Weathers]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getWeathers()
    {
        return $this->hasMany(Weather::class, ['regionId' => 'id']);
    }
}
